`enable_shared_from_this` has a non-virtual destructor
Posted
by Shtééf
on Stack Overflow
See other posts from Stack Overflow
or by Shtééf
Published on 2010-04-03T16:25:48Z
Indexed on
2010/04/03
16:33 UTC
Read the original article
Hit count: 229
I have a pet project with which I experiment with new features of the upcoming C++0x standard. While I have experience with C, I'm fairly new to C++. To train myself into best practices, (besides reading a lot), I have enabled some strict compiler parameters (using GCC 4.4.1):
-std=c++0x -Werror -Wall -Winline -Weffc++ -pedantic-errors
This has worked fine for me. Until now, I have been able to resolve all obstacles. However, I have a need for enable_shared_from_this
, and this is causing me problems. I get the following warning (error, in my case) when compiling my code (probably triggered by -Weffc++
):
base class ‘class std::enable_shared_from_this<Package>’ has a non-virtual destructor
So basically, I'm a bit bugged by this implementation of enable_shared_from_this
, because:
- A destructor of a class that is intended for subclassing should always be virtual, IMHO.
- The destructor is empty, why have it at all?
- I can't imagine anyone would want to delete their instance by reference to
enable_shared_from_this
.
But I'm looking for ways to deal with this, so my question is really, is there a proper way to deal with this? And: am I correct in thinking that this destructor is bogus, or is there a real purpose to it?
© Stack Overflow or respective owner